<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">

<ui:composition template="/WEB-INF/templates/templateMenu.xhtml">

	<ui:define name="body">
		<a4j:form>
			<rich:toolBar>
				<h:outputText styleClass="texto_negrito" value="Cadastro e Manutenção de Ítens de Categoria" />
				<rich:toolBarGroup location="right">
					<a4j:commandLink action="#{itemCategoriaBean.gravar}"
						rendered="#{empty rendered_btgravar ? true : rendered_btgravar}" reRender="tblItensCategoria,panelInsItem">
						<h:graphicImage style="border: none;" url="/imagens/disk.png" />
						<h:outputText value="Gravar" />
					</a4j:commandLink>
				</rich:toolBarGroup>
			</rich:toolBar>
			<h:panelGrid columns="3" id="panelInsItem">
				<h:outputLabel value="Categoria" for="selectCategorias" />
				<h:selectOneMenu label="Categoria"
					value="#{itemCategoriaBean.itensCategoria.categoria.id}"
					id="selectCategorias" required="true">
					<f:selectItem itemLabel="-- Selecione uma categoria --" />
					<f:selectItems value="#{itemCategoriaBean.listaCategorias}" />
				</h:selectOneMenu>
				<rich:message for="selectCategorias" />

				<h:outputLabel value="Ítem de Categoria" for="inItemNome" />
				<h:inputText label="Nome do Ítem"
					value="#{itemCategoriaBean.itensCategoria.nome}" required="true"
					id="inItemNome" />
				<rich:message for="inItemNome" />

				<h:outputLabel value="Descrição do Ítem" for="inItemDescricao" />
				<h:inputText value="#{itemCategoriaBean.itensCategoria.descricao}"
					id="inItemDescricao" />
				<rich:message for="inItemDescricao" />
			</h:panelGrid>
			<rich:separator height="8" width="100%" lineType="beveled"></rich:separator>
			<h:panelGrid width="100%" id="panelItensCategoria">
				<rich:dataTable width="100%" id="tblItensCategoria"
					 var="item" binding="#{itemCategoriaBean.tblItensCategoria}"
					value="#{itemCategoriaBean.listaItensCategoria}" rowClasses="tb_cor2,tb_cor1" rows="10">
					<rich:column>
						<f:facet name="header">
							<h:outputText value="Ítem" />
						</f:facet>
						<h:outputText value="#{item.nome}" />
					</rich:column>

					<rich:column>
						<f:facet name="header">
							<h:outputText value="Descrição" />
						</f:facet>
						<h:outputText value="#{item.descricao}" />
					</rich:column>
					
					<rich:column>
						<f:facet name="header">
							<h:outputText value="Categoria" />
						</f:facet>
						<h:outputText value="#{item.categoria.nome}" />
					</rich:column>

					<rich:column>
						<f:facet name="header">
							<h:outputText value="Ações" />
						</f:facet>
						<h:panelGrid columns="2" cellpadding="5" style="text-align:center;">
							<a4j:commandLink ajaxSingle="true"
								action="#{itemCategoriaBean.delete}" reRender="tblItensCategoria">
								<h:graphicImage border="0" value="/imagens/delete.png" />
								<h:outputText value="Excluir" />
							</a4j:commandLink>

							<a4j:commandLink ajaxSingle="true"	action="#{itemCategoriaBean.edicaoItemCategoria}">
								<h:graphicImage border="0" value="/imagens/edit.png" />
								<h:outputText value="Alterar" />
							</a4j:commandLink>
						</h:panelGrid>
					</rich:column>
				</rich:dataTable>
			</h:panelGrid>
			<rich:datascroller for="tblItensCategoria"/>
		</a4j:form>
	</ui:define>
</ui:composition>

</html>